#include <vector>
#include <string>
#include <algorithm>
using namespace std;
class Solution
{
public:
    bool match(string s, string target)
    {
        int si = 0, ti = 0;
        int size = s.size();
        int tSize = target.size();
        while (si < size)
        {
            if (s[si] == target[ti])
            {
                ti++;
            }
            si++;
            if (ti == tSize)
            {
                return true;
            }
        }
        return false;
    }
    string findLongestWord(string s, vector<string> &dictionary)
    {
        string ans = "";
        int size = dictionary.size();
        for (int i = 0; i < size; i++)
        {
            if (match(s, dictionary[i]))
            {
                if (ans.size() < dictionary[i].size() || (ans.size() == dictionary[i].size() && dictionary[i] < ans))
                {
                    ans = dictionary[i];
                }
            }
        }
        return ans;
    }
};